/*
 * @lc app=leetcode.cn id=11 lang=java
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
class Solution {
    public int maxArea(int[] height) {
        //solution 1
        /*
        int max = 0;
        for (int i = 0; i < height.length -1; i++) {
            for ( int j=i+1; j< height.length; j++ ) {
                int area = Math.min(height[i],height[j]) * (j-i);
                //max = area>max?area:max;
                max = Math.max(area,max);
            }
        }
        return max;
        */

        int max = 0;
        int l = 0;
        int r = height.length - 1;
        while (l < r) {
            int area = Math.min(height[l], height[r]) * (r - l);
            max = Math.max(area, max);
            if (height[l] > height[r]) {
                r--;
            }
            else {
                l++;
            }

        }
       return max;
    }
}
// @lc code=end

